<?php
require_once '../classes/includeAll.php';
require '../resources/getConnection.php';

$search = array ("-", "ae",     "ue",     "oe"    ,"Ae");
$replace = array(" ", "&auml;", "&uuml;", "&ouml;","&Auml;");

$devicesClass = new Devices($connection);
$devices = $devicesClass->getAllDevices();
$connection->disconnectDB();
$head='<link rel="stylesheet" type="text/css" href="../design/css/index.css">'
      .'<script src="../javascript/pagesJavascript/index.js" type="text/javascript"></script>'  ;

$title = "Ger&auml;te Meldungen";
$allNames = Array();
$allMessages = Array();
$allTypes = Array();

require '../menu/head.php';
?>
<h1>Ger&auml;te Meldungen</h1>
<table id="positionTable">
  <tbody>
    <tr>
      <td><table id="notificationsHeader">
          <thead><tr><th><input type="checkbox" name="checkAll" value="all" id="checkAll" /></th><th></th><th>Meldung</th><th>Ger&auml;tetyp</th><th>Name</th></tr></thead>
          </table>
        <div id="notification">
          <form name="flagForm" method="POST" id="flagForm">
          <table id="notificationsList">
            <tbody>
              <?php
              foreach ($devices as $device) {
                if($device->ChangeFlag>0)
                {
                  $n=0;
                  $currentType=$device->DeviceType;
                  
                  if(!in_array($currentType, $allTypes))
                    array_push($allTypes, $currentType);
                  
                  if($device->Name == "")
                    $currentName="-";
                  else
                    $currentName=$device->Name;
                  
                  if(!in_array($currentName, $allNames))
                    array_push($allNames, $currentName);
                  
                  foreach ((new allFlags)->DeviceFlags as $key => $value) {
                    if(($value & $device->ChangeFlag)>0)
                    {
                      $currentMessage =str_replace($search, $replace, $key);
                      if(!in_array($currentMessage, $allMessages))
                        array_push ($allMessages, $currentMessage);
                      
                      echo
                       '<tr style="display: table-row;">'.
                         '<td><input type="checkbox" name="del['.$device->ID.']['.$n.']" value="'.$value.'" class="checkDel" /></td>'.
                         '<td>'.alertLevel($key).'</td>'.
                         '<td><a href="device.php?dev='. $device->ID.'" >'. $currentMessage .'</td>'.
                         '<td><a href="device.php?dev='. $device->ID.'" >'. $device->DeviceType.'</a></td>'.
                         '<td><a href="device.php?dev='. $device->ID.'" >'.$currentName.'</a></td>'.
                       '</tr>';
                      $n++;
                    }
                  }      
                }
              }?>
            </tbody>
          </table>
          </form>
<?php
sort($allMessages);
sort($allTypes);
sort($allNames);
  ?>
        </div></td>
      <td><div id="filterBox">
        <h2>Filter:</h2>
        <table id="filterTable">
          <tbody>
            <tr>
              <td colspan="2">
                <h4>Meldung:</h4>
                <input type="checkbox" name="filterAllNotice" value="" checked="checked" id="filterAllNotice"/> Alle ausw&auml;hlen
                <div class="filterRange">
                  <?php
                  foreach ($allMessages as $message) {
                  echo '<input type="checkbox" name="noteFilter" value="'.$message.'" checked="checked" class="noteFilter"/> '.$message.'<br>';
                  }
                  ?>
                </div></td>
            </tr>
            <tr>
              <td>
                <h4>Ger&auml;t:</h4>
                <select name="singleDev" id="devSelector">
                  <option value="0">Alle Ger&auml;te</option>
                  <?php foreach ($allNames as $name) {
                    echo '<option value="'.$name.'">'.$name.'</option>';
                  } ?>
                </select></td>
                <td>
                  <h4>Ger&auml;tetyp:</h4>
                  <input type="checkbox" name="filterAllDevice" value="" checked="checked" id="filterAllDevice" />Alle ausw&auml;hlen
                  <div class="filterRange">
                    <?php
                  foreach ($allTypes as $type) {
                    echo '<input type="checkbox" name="deviceFilter" value="'.$type.'" checked="checked" class="deviceFilter"/> '.$type.'<br>';
                  }
                  ?>
                </div></td>
            </tr>
          </tbody>
        </table>
        <p>
          <input type="button" value="Entfernen" name="deleteBtn" id="deleteBtn"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span id="picArea"></span>
        </p>
        </div></td>
    </tr>
  </tbody>
</table>
<?php
require '../menu/footer.php';

